package com.wei.czz.common.enums.common.sms;

import com.wei.czz.common.dto.common.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-06-14 15:55:45
 * className: SmsChannelEnum 短信渠道枚举类
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum SmsChannelEnum {

    ALI(1, "阿里云"),

    HW(2, "华为云"),

    TX(3, "腾讯云"),
    ;

    /**
     * 值
     */
    private final Integer value;

    /**
     * 名称
     */
    private final String name;

    /**
     * 获取短信渠道枚举对象
     * @param value 参数值
     * @return 短信渠道枚举对象
     */
    public static SmsChannelEnum get(Integer value) {
        for (SmsChannelEnum channelEnum : values()) {
            if (channelEnum.value.equals(value)) {
                return channelEnum;
            }
        }
        return null;
    }

    /**
     * 获取枚举名称
     * @param value 枚举值
     * @return 名称
     */
    public static String getName(Integer value) {
        for (SmsChannelEnum smsChannelEnum : values()) {
            if (smsChannelEnum.value.equals(value)) {
                return smsChannelEnum.name;
            }
        }
        return "";
    }

    /**
     * 获取枚举列表
     * @return 枚举列表
     */
    public static List<NameValue<Integer>> getList() {
        return Stream.of(values())
                .map(smsChannelEnum -> new NameValue<>(smsChannelEnum.getName(), smsChannelEnum.getValue()))
                .collect(Collectors.toList());
    }

    @Override
    public String toString() {
        return "SmsChannelEnum{" +
                "value=" + value +
                ", name=\"" + name + '"' +
                '}';
    }
}
